import torch

w = torch.tensor([1.],requires_grad=True)

x = torch.tensor([2.],requires_grad=True)

a = torch.add(x,w)

b = torch.add(w,1)

y = torch.mul(a,b)
y.backward()
print(w.grad)